<?php
// 检查客户删除状态
try {
    $pdo = new PDO('mysql:host=127.0.0.1;dbname=oa5', 'root', '123456');
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "=== 检查客户ID=41的状态 ===\n";
    $stmt = $pdo->prepare('SELECT id, name, delete_time, CASE WHEN delete_time = 0 OR delete_time IS NULL THEN "未删除" ELSE "已删除" END as delete_status FROM oa_crm_customer WHERE id = ?');
    $stmt->execute([41]);
    $result = $stmt->fetch(PDO::FETCH_ASSOC);
    echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n\n";
    
    echo "=== 检查所有已删除的记录（前5条）===\n";
    $stmt2 = $pdo->prepare('SELECT id, name, delete_time FROM oa_crm_customer WHERE delete_time > 0 ORDER BY id LIMIT 5');
    $stmt2->execute();
    $deletedRecords = $stmt2->fetchAll(PDO::FETCH_ASSOC);
    echo json_encode($deletedRecords, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n\n";
    
    echo "=== 检查列表API中是否有错误逻辑 ===\n";
    // 模拟列表API的查询条件
    $stmt3 = $pdo->query("SELECT id, name, delete_time FROM oa_crm_customer WHERE (delete_time IS NULL OR delete_time = 0 OR delete_time = '') ORDER BY id DESC LIMIT 10");
    $listRecords = $stmt3->fetchAll(PDO::FETCH_ASSOC);
    echo "列表API查询结果（应该是未删除的记录）:\n";
    echo json_encode($listRecords, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n";
    
} catch (Exception $e) {
    echo "查询失败: " . $e->getMessage() . "\n";
}